﻿/// <reference path="_namespace.js" />

/*****************************************************************************
Ajax library class definition. Kevin Robinson 2008.
Class: ajax.xna.RayCasterMap
/*****************************************************************************/

$addNamespace("ajax.xna");

$imports("ajax.math.Ray");
$imports("ajax.math.Vector3");

ajax.xna.RayCasterLookups = function(size)
{
    this.createTables(size);
}
ajax.xna.RayCasterLookups.prototype = 
{
    screenScanX: [],
    screenScanY: [],
    rays: [],    
    rayOffsets: [],
    mapPoints: [],
    sideDistances: [],
    deltaDistances: [],
    perpWallDistances: [],
    steps: []        
};

ajax.xna.RayCasterLookups.prototype.createTables = function(size)
{    
    this.screenScanX        = new Array(parseInt(size.width));
    this.screenScanY        = new Array(parseInt(size.height));
    this.rays               = new Array(parseInt(size.width));
    this.rayOffsets         = new Array(parseInt(size.width));
    this.mapPoints          = new Array(parseInt(size.width));
    this.sideDistances      = new Array(parseInt(size.width));
    this.deltaDistances     = new Array(parseInt(size.width));
    this.perpWallDistances  = new Array(parseInt(size.width));
    this.steps              = new Array(parseInt(size.width));
        
    for (var x = 0; x < size.width; x++)   
    { 
        this.screenScanX[x]         = 2 * x / parseFloat(size.width) - 1; 
        this.rays[x]                = new ajax.math.Ray(new ajax.math.Vector3(), new ajax.math.Vector3());
        this.rayOffsets[x]          = new ajax.math.Vector3();
        this.mapPoints[x]           = new ajax.drawing.Point(0, 0);
        this.sideDistances[x]       = new ajax.math.Vector3();
        this.deltaDistances[x]      = new ajax.math.Vector3();
        this.perpWallDistances[x]   = 0;
        this.steps[x]               = new ajax.math.Vector3();
    }  
    
    for (var y = 0; y < size.height; y++)
        this.screenScanY[y] = size.height / (2.0 * y - size.height); 
           
}
